import json

from api.base_service import BaseService



class MemberServiceAPI(BaseService):
    def __init__(self):
        super().__init__()
        self.member_service = "MemberService"

    # 根据手机号查询会员信息
    def find_by_telephone(self,tel):
        resp = self.client.invoke(self.member_service,"findByTelephone",tel)
        if resp == "Failed" or resp == "null":
            return None
        else:
            return json.loads(resp)

    def find_member_count_by_months(self, list_data):
        resp = self.client.invoke(self.member_service,"findMemberCountByMonths",list_data)
        if resp == "Failed" or resp == "No":
            return None
        else:
            return json.loads(resp)

    def add(self,dict_data):
        dict_data["class"] = "com.itheima.pojo.Member"
        resp = self.client.invoke(self.member_service,"add",dict_data)

        if resp == "null":
           return True
        else:
           return  False



if __name__ == '__main__':

    ms = MemberServiceAPI()
    # 根据手机号查询会员信息
    resp = ms.find_by_telephone("13020210001")
    print("响应信息:",resp)
    print("响应类型:",type(resp))
# 根据日期查询会员信息
    print("*" * 30)
    resp = ms.find_member_count_by_months(["2021.7"])
    print("响应信息:", resp)
    print("响应类型:", type(resp))
# 添加会员
    dict_data = {"id":12345,"name":"保温杯","phoneNumber":"18834500234"}
    resp = ms.add(dict_data)
    print("响应信息:", resp)
    print("响应类型:", type(resp))


